/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.arquillian.example;

import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author Administrator
 */
@Stateless
public class GameEJB extends BaseJPAUnitEJB<Game,Long>{

//    @PersistenceContext(unitName = "test")
//    EntityManager em;

    private static final String[] GAME_TITLES = {
        "Super Mario Brothers",
        "Mario Kart",
        "F-Zero"
    };

    public void insertData() throws Exception {

//        System.out.println("Inserting records...");
        this.logger.debug("Inserting records...");
        for (String title : GAME_TITLES) {
            Game game = new Game(title);
           // em.persist(game);
            this.persist(game);
        }

    }

    public void clearData() throws Exception {
//        System.out.println("Dumping old records...");
         this.logger.debug("Dumping old records...");
        //em.createQuery("delete from Game").executeUpdate();
        this.remove(this.findAll());
    }

    public List<Game> getAll() {
//        String fetchingAllGamesInJpql = "select g from Game g order by g.id";
//        return em.createQuery(fetchingAllGamesInJpql, Game.class).getResultList();
        return this.findAll();
    }
}
